//
//  HWMineInfoVipCell.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/8/23.
//  Copyright © 2022 94Wan. All rights reserved.
//

import UIKit

class HWMineInfoVipCell: UICollectionViewCell {
    var bgImageView:UIImageView!
    var contentLabel:UILabel!
    var openBgView:UIView!
    var openLabel:UILabel!
    var progressBarBg:UIView!
    var progressBar:YLProgressBar!
    var upgradeSurplusLabel:UILabel!
    var model:HWMineHuiYuanModel? {
        didSet {
            bgImageView.kf.setImage(with: URL(string: model?.bg ?? ""))
            contentLabel.text = model?.text
            if model?.is_huiyuan == false {
                openLabel.text = "未开通"
                openLabel.isHidden = false
                openBgView.isHidden = false
                progressBar.isHidden = true
                progressBarBg.isHidden = true
                upgradeSurplusLabel.isHidden = true
                contentLabel.snp.updateConstraints { make in
                    make.top.equalTo(37*widthScale)
                }
            } else {
                openLabel.isHidden = true
                openBgView.isHidden = true
                progressBar.isHidden = false
                progressBarBg.isHidden = false
                upgradeSurplusLabel.isHidden = false
                contentLabel.snp.updateConstraints { make in
                    make.top.equalTo(69*widthScale)
                }
                
                progressBar.progress = CGFloat(model?.exp ?? 0) / CGFloat(model?.last_exp ?? 0)
                upgradeSurplusLabel.text = "成长值：\(model?.exp ?? 0)/\((model?.last_exp ?? 0))"
            }
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initUI()
        
        initFrame()
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension HWMineInfoVipCell {
    private func initUI() -> Void {
        bgImageView = UIImageView()
        bgImageView.backgroundColor = .clear
        bgImageView.layer.masksToBounds = true
        contentView.addSubview(bgImageView)
        
        contentLabel = HWLabel.createLabel(title: "", color: "#888888", font: 11*widthScale)
        contentView.addSubview(contentLabel)
        
        openBgView = UIView()
        openBgView.backgroundColor = .colorWithHexString(hexString: "#232323")
        openBgView.layer.cornerRadius = 11*widthScale
        openBgView.layer.masksToBounds = true
        contentView.addSubview(openBgView)
        
        openLabel = HWLabel.createBoldLabel(title: "未开通", color: "#1CD67E", font: 11*widthScale)
        openBgView.addSubview(openLabel)
        
        progressBarBg = UIView()
        progressBarBg.layer.cornerRadius = 2*widthScale
        progressBarBg.backgroundColor = .colorWithAlphaHexString(hexString: "#1CD67E", alpha: 0.13)
        progressBarBg.layer.masksToBounds = true
        addSubview(progressBarBg)
        
        progressBar = YLProgressBar()
        progressBar.indicatorTextDisplayMode = .none
        progressBar.progressTintColors = [UIColor.colorWithHexString(hexString: "#1CD67E")]
        progressBar.trackTintColor = .clear
        progressBar.hideStripes = true
        progressBar.progress = 0
        progressBar.hideGloss = true
        progressBar.progressStretch = true
        progressBar.progressBarInset = 0
        addSubview(progressBar)
        
        upgradeSurplusLabel = HWLabel.createBoldLabel(title: "", color: "#1CD67E", font: 9*widthScale)
        contentView.addSubview(upgradeSurplusLabel)
    }
    
    private func initFrame() -> Void {
        bgImageView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        contentLabel.snp.makeConstraints { make in
            make.left.equalTo(12*widthScale)
            make.top.equalTo(37*widthScale)
            make.height.equalTo(15*widthScale)
        }
        
        openBgView.snp.makeConstraints { make in
            make.left.equalTo(11*widthScale)
            make.bottom.equalTo(-5*widthScale)
            make.height.equalTo(22*widthScale)
        }
        
        openLabel.snp.makeConstraints { make in
            make.left.equalTo(15*widthScale)
            make.right.equalTo(-15*widthScale)
            make.centerY.equalToSuperview()
        }
        
        progressBarBg.snp.makeConstraints { make in
            make.left.equalTo(11*widthScale)
            make.top.equalTo(43*widthScale)
            make.width.equalTo(145*widthScale)
            make.height.equalTo(4*widthScale)
        }
        
        progressBar.snp.makeConstraints { make in
            make.left.equalTo(11*widthScale)
            make.top.equalTo(43*widthScale)
            make.width.equalTo(145*widthScale)
            make.height.equalTo(4*widthScale)
        }
        
        upgradeSurplusLabel.snp.makeConstraints { make in
            make.left.equalTo(11*widthScale)
            make.top.equalTo(48*widthScale)
            make.height.equalTo(13*widthScale)
        }
    }
}
